package com.bookcode.dao;


import com.bookcode.entity.Sign;
import com.bookcode.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.Column;
import java.util.Date;
import java.util.List;


public interface SignRepository extends JpaRepository<Sign,Long> {
//    @Column(name = "course_id")
//    private String courseId;//课程id
//    @Column(name = "sign_key")
//    private Date sign_key;//签到码
//    @Column(name = "state")
//    private Date state;//状态，是否可签到
//    @Column(name = "sign_time")
//    private Date time;//签到码开始时间
    //查询出最新的签到码
    @Query(nativeQuery=true,value = "select * from t_sign_key  where course_id = :courseId order by sign_time desc limit 1")
   Sign findSignCodeByCourseId(@Param("courseId") String courseId);
    //停止签到
    @Modifying
    @Query(nativeQuery=true,value = "update t_sign_key  set state= false where course_id=:courseId order by sign_time desc limit 1")
    void undateState(@Param("courseId") String courseId);


    /**
     * 根据课程查询发起的签到
     */
//    @Query("from Sign s where s.courseId=:courseId")
//    List<Sign> findSignsByCourse(@Param("courseId") Long courseId);

    /**
     *
     * 查找未结束的发起的签到
     */
//    @Query("from Sign s where s.courseId=:courseId and s.end=false")
//    List<Sign> findSignsNotEndByCourse(@Param("courseId") Long courseId);
}
